/*
This Software is distributed with the following X11 License,
sometimes also known as MIT license.
 
Copyright (c) 2010 Miguel A. Ballicora

 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation
 files (the "Software"), to deal in the Software without
 restriction, including without limitation the rights to use,
 copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following
 conditions:

 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
*/

#if !defined(H_GTBPROBE)
#define H_GTBPROBE

/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/

#include <stdlib.h>
#include "Bool.h"

namespace Tablebases
{


#define tb_MAXPATHLEN 1024


/*----------------------------------*\
|         	FUNCTIONS
\*----------------------------------*/

extern char *		tb_init   (int verbosity, int compression_scheme, const char **paths);

extern char *		tb_restart(int verbosity, int compression_scheme, const char **paths);

extern void			tb_done (void);

extern int /*bool*/	tb_probe_hard 
							(uint8_t cl, 
							BitBoard* q,				
			 				 /*@out@*/ unsigned *tbinfo, 
			 				 /*@out@*/ unsigned *plies);

extern int /*bool*/	tb_probe_soft 
							(uint8_t cl, 
							BitBoard* q,		 
			 				 /*@out@*/ unsigned *tbinfo, 
			 				 /*@out@*/ unsigned *plies);

extern int /*bool*/	tb_probe_WDL_hard 
							(uint8_t cl, 
							BitBoard* q,				
			 				 /*@out@*/ unsigned *tbinfo); 

extern int /*bool*/	tb_probe_WDL_soft 
							(uint8_t cl, 
							 BitBoard* q,		 
			 				 /*@out@*/ unsigned *tbinfo);

extern int /*bool*/	tb_is_initialized (void);

/* 	
|	tb_availability() returns 0 if no TBs available 
|	Otherwise, the following bits are turned 'on' if...
|	----------------------------------
|	bit: meaning
|	----------------------------------
|	0: at least one 3-pc TB is present
|	1: 3-pc TBs are complete
|	2: at least one 4-pc TB is present
|	3: 4-pc TBs are complete
|	4: at least one 5-pc TB is present
|	5: 5-pc TBs are complete
|	6: at least one 6-pc TB is present
|	7: 6-pc TBs are complete
|	Example: if 63 is returned, it means all 3-4-5-pc TBs are present
|	Bits 6 and 7 will be always off, of course, until 6-piece TBs
|	are supported.
*/

extern unsigned int	tb_availability(void);

/* 	
|	tb_indexmemory ()returns 
|	how much memory has been allocated for indexes 
*/

extern size_t		tb_indexmemory (void);

/*----------------------------------*\
|         	cache
\*----------------------------------*/

extern int /*bool*/	tbcache_init    (size_t cache_mem, int wdl_fraction);
extern int /*bool*/	tbcache_restart (size_t cache_mem, int wdl_fraction);
extern void			tbcache_done (void);
extern int /*bool*/	tbcache_is_on (void);
extern void			tbcache_flush (void);

/*----------------------------------*\
|         	STATS
\*----------------------------------*/

/*
|	For maximum portability, some stats are provided
|	in two 32 bits integers rather than a single 64 bit number. 
|	For intance, prob_hard_hits[0] contains the less significant 32 bits 
|	(0 to 31), and prob_hard_hits[1] the most significant ones (32 to 63). 
|	The 64-bit number can be recreated like this:
|	uint64_t x;
|	x = (uint64_t)probe_hard_hits[0]|((uint64_t)probe_hard_hits[1]<<32);
|	The user has the responsibility to combine the numbers and use the 
|	proper 64 bit integers.
*/


extern void			tbstats_reset (void);
extern void 		tbstats_get (struct TB_STATS *stats);


/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
}
#endif
